package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.Dish;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.ShoppingCartService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "C端-购物车接口")
public class shoppingCartController
{
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 购物车添加商品功能
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("购物车添加接口")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        log.info("添加进购物车的商品为：{}",shoppingCartDTO);
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据用户id和商品id查询购物车接口")
    public Result<List<ShoppingCart>> showShoppingCart()
    {
        List<ShoppingCart> list=shoppingCartService.showShoppingCart();
        return Result.success(list);
    }

    @PostMapping("/sub")
    @ApiOperation(value = "减少购物车中的一个商品")
    public  Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        shoppingCartService.sub(shoppingCartDTO);
        return Result.success();
    }


    /**
     * 清楚购物车内的所有商品
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation(value = "清空购物车")
    public  Result clean()
    {
        shoppingCartService.clean();
        return Result.success();
    }
}
